#ifndef SUFFER_H
#define SUFFER_H

#include <QDialog>
#include <QLabel>
#include <QKeyEvent>
#include <QTimer>
#include <QPainter>

class PlayerModel {
public:
    PlayerModel(QWidget *parent = nullptr) {}

    QLabel *player;
    int x = 200;
    int y = 200;
    int width = 10;
    int height = 10;
    int gravity = 0;
//    int jumping = 0;
//    int jumpSpeed = 6;
    int love = 3;

    bool keyUp = false;
    bool keyRight = false;
    bool keyDown = false;
    bool keyLeft = false;

    void moveUp(int minHeight, int speed = 4)
    {
        if (y > minHeight)
        {
            y -= speed;
            player->move(x, y);
        }
    }
    void moveDown(int maxHeight, int speed = 4)
    {
        if (y < maxHeight)
        {
            y += speed;
            player->move(x, y);
        }
    }
    void moveLeft(int minHeight, int speed = 4)
    {
        if (x > minHeight)
        {
            x -= speed;
            player->move(x, y);
        }
    }
    void moveRight(int maxWidth, int speed = 4)
    {
        if (x < maxWidth)
        {
            x += speed;
            player->move(x, y);
        }
    }
//    void jump(int direction)
//    {
//        switch (direction)
//        {
//        case 1:
//            moveDown(1000, jumpSpeed);
//            jumpSpeed = jumpSpeed - 1;
//            if (jumpSpeed == -7)
//            {
//                jumpSpeed = 6;
//                jumping = 0;
//            }
//            break;
//        case 2:
//            moveLeft(0, jumpSpeed);
//            jumpSpeed = jumpSpeed - 1;
//            if (jumpSpeed == -7)
//            {
//                jumpSpeed = 6;
//                jumping = 0;
//            }
//            break;
//        case 3:
//            moveUp(0, jumpSpeed);
//            jumpSpeed = jumpSpeed - 1;
//            if (jumpSpeed == -7)
//            {
//                jumpSpeed = 6;
//                jumping = 0;
//            }
//            break;
//        case 4:
//            moveRight(0, jumpSpeed);
//            jumpSpeed = jumpSpeed - 1;
//            if (jumpSpeed == -7)
//            {
//                jumpSpeed = 6;
//                jumping = 0;
//            }
//            break;
//        }
//    }
};
class Obstacle {
public:
    Obstacle(QWidget *parent = nullptr) {};

    QLabel *helloW;
    int x;
    int y;
    int size = 20;

    void moveUp(int minHeight, int speed = 4)
    {
        if (y > minHeight)
        {
            y -= speed;
            helloW->move(x, y);
        }
    }
    void moveDown(int maxHeight, int speed = 4)
    {
        if (y < maxHeight)
        {
            y += speed;
            helloW->move(x, y);
        }
    }
    void moveLeft(int minHeight, int speed = 4)
    {
        if (x > minHeight)
        {
            x -= speed;
            helloW->move(x, y);
        }
    }
    void moveRight(int maxWidth, int speed = 4)
    {
        if (x < maxWidth)
        {
            x += speed;
            helloW->move(x, y);
        }
    }
};

class Suffer : public QDialog
{
    Q_OBJECT

public:
    Suffer(QWidget *parent = nullptr);
    ~Suffer();

    void playerMove();
    void createHello();
    void gameOver();

protected:
    void paintEvent(QPaintEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void closeEvent(QCloseEvent *event);

private:
    int sufferWidth = 400;
    int sufferHeight = 400;
    int num = 0;
    QString words[38] = {
        "天空是黑暗的", "心里空空的", "我感觉到好像", "全世界都抛弃了我", "孤独", "寂寞", "失落", "将我压的喘不过气来...",
        "把支离破碎的句子", "组成忧伤的画", "看到就揪心！", "听那悲伤的旋律", "猜测你的心事", "看世界模糊点好", "看的太清楚", "伤的越痛苦！",
        "现实的社会", "我们还是虚幻点比较好！", "要么生活会把我们", "糟蹋的遍体躏伤！",
        "窗外雨在下", "一颗挨着一颗", "我的泪水也", "如窗外那断了线的雨珠",
        "寂寞的人", "总是会用心", "记住他生命中", "出现过的每一个人", "于是我总是意犹未尽地想起", "你在每个星光陨落的晚上", "一遍一遍数我的寂寞",
        "谢谢你", "听完我的诉说", "可是作者", "已经把后面咕掉了", "如果还有序章", "那我只能说", "下次一定"
    };

    QLabel *label_1;
    QLabel *labelGameOver;

    QTimer *timer_1;
    QTimer *timer_2;

    PlayerModel *playerModel;
    Obstacle *hello[50];
};

#endif // SUFFER_H
